package com.syh.jn.scm.service.impl.supplier.base;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.supplier.entity.base.SupplierBankAccount;
import com.syh.jn.scm.domain.supplier.repository.base.SupplierBankAccountRepository;
import com.syh.jn.scm.dto.supplier.base.bankAccount.BankAccountMto;
import com.syh.jn.scm.dto.supplier.base.bankAccount.BankAccountSto;
import com.syh.jn.scm.dto.supplier.base.bankAccount.BankAccountVo;
import com.syh.jn.scm.service.api.supplier.base.BankAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BankAccountServiceImpl extends AbstractServiceImpl<BankAccountSto, BankAccountMto, BankAccountVo, SupplierBankAccount, Long> implements BankAccountService {

  @Autowired
  private SupplierBankAccountRepository supplierBankAccountRepositoryImpl;

  @Override
  protected AggregateRepository<SupplierBankAccount, Long> getAggregateRepository() {
    return supplierBankAccountRepositoryImpl;
  }

  /**
   * 保存对象
   * @param sto
   * @return
   */
  @Override
  public Long save(BankAccountSto sto) {
    SupplierBankAccount account = SupplierBankAccount.createBusiness(sto);
    return supplierBankAccountRepositoryImpl.add(account);
  }

  /**
   * 修改对象
   * @param mto
   */
  @Override
  public void update(BankAccountMto mto) {
    SupplierBankAccount account = supplierBankAccountRepositoryImpl.getById(mto.getId());
    account.modify(mto);
    supplierBankAccountRepositoryImpl.update(account);
  }

  /**
   * 删除对象
   * @param id
   */
  @Override
  public void delete(Long id) {
    SupplierBankAccount account = supplierBankAccountRepositoryImpl.getById(id);
    account.destroy();
    supplierBankAccountRepositoryImpl.remove(account);
  }

  /**
   * 启用
   * @param id
   */
  @Override
  public void enabled(Long id) {
    SupplierBankAccount account = supplierBankAccountRepositoryImpl.getById(id);
    account.enabled();
    supplierBankAccountRepositoryImpl.update(account);
  }

  /**
   * 停用
   * @param id
   */
  @Override
  public void disabled(Long id) {
    SupplierBankAccount account = supplierBankAccountRepositoryImpl.getById(id);
    account.disabled();
    supplierBankAccountRepositoryImpl.update(account);
  }
}
